package com.yanqu.road.server.cmd.passRoad;

import com.yanqu.road.pb.pass.RoadProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.config.PassRoadMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.string.StringUtils;

import java.util.List;

@Cmd(code = Protocol.S_PASS_ROAD_DISPATCH_TEST, desc = "派遣测试")
public class PassRoadDispatchTestCmd extends AbstractCommand {

	private int star= 0;
	//string
	private String param;
	//派遣的门客列表
	private List<Integer> patronIdList;
	//赔钱的美女列表
	private List<Integer> beautyIdList;

	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		RoadProto.DispatchTestReqMsg reqMsg = RoadProto.DispatchTestReqMsg.parseFrom(packet.getBytes());
		param = reqMsg.getParam();
		patronIdList = reqMsg.getPatronIdList();
		beautyIdList = reqMsg.getBeautyIdList();
		return true;
	}

	@Override
	public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
		List<String> paramsList = StringUtils.stringToStringList(param,"-");
		List<String> conditionList = StringUtils.stringToStringList(paramsList.get(1),"\\|");
		for(String condition : conditionList){
			List<Integer> paramList = StringUtils.stringToIntegerList(condition,";");
			if(paramList.size() != 4){
 				ret = 10086;
 				return;
			}
		}
		star = PassRoadMgr.getEventDispatchStar(player,paramsList.get(1),patronIdList,beautyIdList);
	}

	@Override
	public void sendData(GamePlayer player) {
		RoadProto.DispatchTestRespMsg.Builder respMsg = RoadProto.DispatchTestRespMsg.newBuilder();
		respMsg.setRet(ret);
		respMsg.setStar(star);
		player.sendPacket(Protocol.U_PASS_ROAD_DISPATCH_TEST, respMsg);
	}
}
